<?php
/**
 * Display Mission Candidat Workflow
 * and add handling features.
 * 
 * @author Xavier VILAIN
 * @package Hive\Mission
 * 
 */
use Fox\Html\Header\Content;
$xview = Xview::instance();
/* @var $mission Hive\Mission */
$mission = $xview->component("missions", "object");
// Customizing
$customizing = Hive\Mission\Customizing::instance();
$customizing->trackSummaryPage(array('mod' => 'missions','act'=>'process'));
$mid = $mission->getId();
// Page Title
$header = new Content('process',Msg(Hive::BUNDLE,Hive::MENU_PROCESS));

// Load Different Workflow Steps
/* @var $worflow Hive\Workflow */
$worflow = $mission->workflow();
/* @var $tree Fox\Node */
list($tree,$nodes) = $worflow->tree();

$items = array();
// Load Candidate Partners & Their Status to repart
// them in the correct workflow step

foreach($mission->candidates() as $candidate) {
	
	$id = $candidate->partnerid;
	$content = $candidate->contact()->name();
	$content =  '<div class="ui-drag"><span class="icon-bar"></span><span class="icon-bar"></span><span class="icon-bar"></span></div><a href="?mod=ressource&act=main&rid='.$id.'" target="_blank">'.$content.'</a>';
	$items[$candidate->status][] = array('html' => $content,'contactid' => $candidate->partnerid,'missionid' => $mid);
}
$html = $worflow->render($tree,$items);
// Deleting Part
$removedList = null;
$step = $worflow->exclusionStep();
$stepid = $step->stepid;
if(isset($items[$stepid])) {
	foreach($items[$stepid] as $item ) {
		$removedList .= '<li class="ui-state-default ui-draggable {\'contactid\':'.$item['contactid'].',\'missionid\':'.$item['missionid'].'}">'.$item['html'].'</li>';
	}
}

$htmlRemove = '<div class="mission-step removed-area">
			<span class="ui-widget-header">'.$step->label().'</span>
			<ul id="workflow_'.$stepid.'" class="ui-sortable" data-status="'.$stepid.'">'.$removedList.'</ul></div>';
		
?>
<div id="process">
	<div><?php echo $header->render();?></div>
	<div class="process-contentArea">
		<div class="mbs col1">
				<?php echo $html;?>
		</div>
		<div class="mbs col2">
				<?php echo $htmlRemove;?>
		</div>
	</div>
</div>
